package utils;

import java.io.IOException;
import java.io.OutputStream;

import javax.swing.JTextArea;

/*
 * Class used by gui.IOpenSSL.java
 * Update JTextArea widget when there is something to read
 */
public class JTextAreaOutputStream extends OutputStream {

	private JTextArea area;
	
	public JTextAreaOutputStream(JTextArea area) {
		super();
		this.area=area;
	}
	
	@Override
	public void write(int i) throws IOException {
		String s = Character.toString((char)i);
        String data=this.area.getText();
        data+=s;
        this.area.setText(data);
	}
	
	@Override
	public void write(byte[] arg0, int arg1, int arg2) throws IOException {
		String s=new String(arg0, arg1, arg2);
		String data=this.area.getText();
        data+=s;
        this.area.setText(data);
	}
	
	@Override
	public void write(byte[] b) throws IOException {
        String data=this.area.getText();
        data+=new String(b);;
        this.area.setText(data);
	}
}
